package api

import (
	"server/global"
	"server/model/common/response"
	"server/plugin/mall/model"
	"server/plugin/mall/model/request"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

var A轮播 = new(lunbo)

type lunbo struct{}

// CreateA轮播 创建轮播
// @Tags A轮播
// @Summary 创建轮播
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.A轮播 true "创建轮播"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /lunbo/createA轮播 [post]
func (a *lunbo) CreateA轮播(c *gin.Context) {
	var info model.A轮播
	err := c.ShouldBindJSON(&info)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = serviceA轮播.CreateA轮播(&info)
	if err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("创建成功", c)
}

// DeleteA轮播 删除轮播
// @Tags A轮播
// @Summary 删除轮播
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.A轮播 true "删除轮播"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /lunbo/deleteA轮播 [delete]
func (a *lunbo) DeleteA轮播(c *gin.Context) {
	ID := c.Query("ID")
	err := serviceA轮播.DeleteA轮播(ID)
	if err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteA轮播ByIds 批量删除轮播
// @Tags A轮播
// @Summary 批量删除轮播
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /lunbo/deleteA轮播ByIds [delete]
func (a *lunbo) DeleteA轮播ByIds(c *gin.Context) {
	IDs := c.QueryArray("IDs[]")
	err := serviceA轮播.DeleteA轮播ByIds(IDs)
	if err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateA轮播 更新轮播
// @Tags A轮播
// @Summary 更新轮播
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.A轮播 true "更新轮播"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /lunbo/updateA轮播 [put]
func (a *lunbo) UpdateA轮播(c *gin.Context) {
	var info model.A轮播
	err := c.ShouldBindJSON(&info)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = serviceA轮播.UpdateA轮播(info)
	if err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindA轮播 用id查询轮播
// @Tags A轮播
// @Summary 用id查询轮播
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query model.A轮播 true "用id查询轮播"
// @Success 200 {object} response.Response{data=model.A轮播,msg=string} "查询成功"
// @Router /lunbo/findA轮播 [get]
func (a *lunbo) FindA轮播(c *gin.Context) {
	ID := c.Query("ID")
	relunbo, err := serviceA轮播.GetA轮播(ID)
	if err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:"+err.Error(), c)
		return
	}
	response.OkWithData(relunbo, c)
}

// GetA轮播List 分页获取轮播列表
// @Tags A轮播
// @Summary 分页获取轮播列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query request.A轮播Search true "分页获取轮播列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /lunbo/getA轮播List [get]
func (a *lunbo) GetA轮播List(c *gin.Context) {
	var pageInfo request.A轮播Search
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := serviceA轮播.GetA轮播InfoList(pageInfo)
	if err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败:"+err.Error(), c)
		return
	}
	response.OkWithDetailed(response.PageResult{
		List:     list,
		Total:    total,
		Page:     pageInfo.Page,
		PageSize: pageInfo.PageSize,
	}, "获取成功", c)
}

// GetA轮播Public 不需要鉴权的轮播接口
// @Tags A轮播
// @Summary 不需要鉴权的轮播接口
// @accept application/json
// @Produce application/json
// @Param data query request.A轮播Search true "分页获取轮播列表"
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /lunbo/getA轮播Public [get]
func (a *lunbo) GetA轮播Public(c *gin.Context) {
	// 此接口不需要鉴权 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
	serviceA轮播.GetA轮播Public()
	response.OkWithDetailed(gin.H{"info": "不需要鉴权的轮播接口信息"}, "获取成功", c)
}
